"""
plots.py

Thu Oct 11 11:12:18 CEST 2012
"""

from matplotlib.pyplot import figure, show
import numpy as np
def raster_plot(nparray):
    """
    plot a raster plot as in Fig 2 from Gibson & Robison, 1992

    nparray     a 2D NumPy array with the zeros and ones

    
    """
    fig = figure(1)
    ax = fig.add_subplot(111)

    for i in range(nparray.shape[0]):
            xdata = np.ones(nparray.shape[1])*i
            ydata = (nparray[i]>0).choose(np.nan, 1)
            ydata = ydata*range(1, len(ydata)+1)  #transform ones in indices
            ax.plot(xdata, ydata, '|', color='k',  rasterized=True, markeredgewidth=2, markersize=2)
    

    ax.set_xlim(xmin = -0.5, xmax=i+1)
    ax.set_ylim(ymax = nparray.shape[1])
    ax.set_ylabel('Number of active neurons')
    ax.set_xlabel('Recall step')
    show()


if __name__ == '__main__':
    import numpy as np

    X = np.array([1,1,0,0,0,1,1,1,1,0],dtype=int)
    for _ in range(5):
        Y = np.array([1,1,0,0,0,1,0,1,0, 1],dtype=int)
        X = np.vstack((X, Y))
    
    raster_plot(X.T)
        

